<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Siggraph Sort App Results</title>

<link rel="stylesheet" href="css/jq.css" type="text/css"
	media="print, projection, screen" />
<link rel="stylesheet" href="css/themes/blue/style.css" type="text/css"
	media="print, projection, screen"/>

<script type="text/javascript" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="js/addons/pager/jquery.tablesorter.pager.js"></script>
<script type="text/javascript" src="js/sismenus.js"></script>
<script type="text/javascript" id="sis">
window.onload = function()
{
    sisMenus(document.body);
}
</script>

<script type="text/javascript" id="js">
    $(document).ready(function() {
	$("#Results").tablesorter({
	    widgets: ['zebra']
	}).tablesorterPager({
	    container:$("#pager"),
	    size:25,
	    positionFixed: false,
	});
	$("#FullTable").tablesorter({
	    widgets: ['zebra']
	});
    });
</script>
</head>

<body>

<?php

$vars = array();
if (isset($_GET['q']))
       $vars['q'] = $_GET['q'];
if (isset($_GET['id']))
       $vars['id'] = $_GET['id'];

printf('<h3 align="center">Siggraph Sorting App</h3>');
require_once("header.php");

$args = "s";
$cmd = "";
if (empty($vars['q']))
        $vars['q']='empty';

switch ($vars['q']) {
    case 's':
	$args = "s";
	$cmd = 'display.py';
	break;
    case 'r':
	$args = "r";
	$cmd = 'display.py';
	break;
    case 'a':
	$args = "a";
	$cmd = 'display.py';
	break;
    case 'rt':
	$args = sprintf("rt %s", $vars['id']);
	$cmd = 'display.py';
	break;
    case 'si':
	$args = sprintf("si %s", $vars['id']);
	$cmd = 'display.py';
	break;
    case 'ri':
	$args = sprintf("ri %s", $vars['id']);
	$cmd = 'display.py';
	break;
    case 'rtop':
	$args = sprintf("rtop %s", $vars['id']);
	$cmd = 'display.py';
	break;
    case 'run':
	printf('<h3 align="center">Results</h3>');
	system("/usr/bin/python display.py run");
        printf("<listing>");
        $fp = fopen("run/report.txt", "r");
        while (!feof($fp))
            printf("%s", fgets($fp));
        fclose($fp);
        printf("</listing>");
	break;
    case 'upload':
	printf('<h3 align="center">Generating Upload File</h3>');
	system("/usr/bin/python display.py upload");
        printf("<listing>");
        $fp = fopen("sis-upload.txt", "r");
        while (!feof($fp))
            printf("%s", fgets($fp));
        fclose($fp);
        printf("</listing>");
	break;
    case 'empty':
        print "";
    default:
        if ($vars['q']!='empty') {
	        $args = $vars['q'];
        	$cmd = 'display.py';
	}
}

if ($cmd)
{
    $cmd = sprintf("/usr/bin/python %s %s", $cmd, $args);
    system($cmd);
}

?>
</body>
</html>
